/* *************************************** */
/* * PPM File Creator                    * */
/* * Authors:                            * */
/* *  André Bannwart Perina      7152757 * */
/* *  Rodrigo de Freitas Pereira 7573472 * */
/* *  Thaís Emanuele dos Santos  6453087 * */
/* *************************************** */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
	/* Incorrect number of arguments */
	if(argc != 4) {
		fprintf(stderr, "Usage: %s width length outputFile\n", argv[0]);
		return EXIT_FAILURE;
	}

	int width = atoi(argv[1]), length = atoi(argv[2]), i, j;
	FILE *ipf = fopen(argv[3], "w");

	/* Failed to open file */
	if(!ipf) {
		fprintf(stderr, "%s: %s: %s\n", argv[0], argv[3], strerror(errno));
		return EXIT_FAILURE;
	}

	/* Set header */
	fprintf(ipf, "P3\n%d %d\n255\n", width, length);

	/* Set all white */
	for(i = 0; i < width; i++) {
		for(j = 0; j < length; j++)
			fprintf(ipf, "255 255 255 ");
		fprintf(ipf, "\n");
	}

	/* Close file */
	fclose(ipf);

	return EXIT_SUCCESS;
}